<?php include "../public/header.php";?>
<?php include "../public/header_edit.php";?>
<style>
    .hang{margin-top: 15px;border: 1px solid #ccc;width: calc(100% - 60px);margin-left: 30px}
    .mmtit{width: calc(50% - 30px);float: left;padding-left: 30px;}
    #mmleft{float: left;width: calc(50% - 5px);background-color: #eee;padding: 20px 0;}
    #mmright{float: left;width: calc(50% + 5px);padding: 20px 0;}
    .mmlock{border: 1px solid #ccc;color: #333;}
    .mmlock .con{margin: 8px 10px}
    #mmleft .layui-input-block {min-height: 33px !important;}
    #mmleft .layui-form-label {background-color: #eee;border: unset}


    .show-minimg .li{width: 100px;height: 120px;text-align: center;border: 1px solid #E4E4E4;cursor: pointer;
        position: relative;float: left;margin-right: 15px;margin-bottom: 15px;color: #E4E4E4}
    .show-minimg .lilan{border: 1px solid #409EFF;color: #409EFF}
    .show-minimg .li img{height: 100%;width: 100%}
    .show-minimg .li .imgdiv{width: 98px;height: 90px}
    .show-minimg .li .imgdiv i{font-size: 40px;margin-top: 30px;}
    .show-minimg .filetit{color: #777777;text-align: center;line-height: 30px;overflow: hidden;
        text-overflow:ellipsis;white-space: nowrap;padding: 0 10px;}
    .show-minimg .li .cheng{display: none}
    .show-minimg .li .cheng .shan{color: #F56C6C;font-size: 25px;position: absolute;top: -15px;right: -16px}
    .show-minimg .li .jia{font-size: 40px;}
    .show-minimg .li .dea-ext{font-size: 35px;padding-top: 20px}
</style>

<body id="optPage">
<form class="layui-form layui-form-pane" id="commentForm">
    <div class="page-title"><div class="page-title-con"><span>整改回复</span><div class="move_title"></div><?php include "../public/sub.php";?></div></div>
    <div class="main-container">

        <div class="block-generic">


            <div class="layui-form-item">
                <div class="layui-row layui-col-space10">
                    <div class="edittits"><span>基本信息</span></div>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md6">
                        <label class="layui-form-label">项目名称</label>
                        <div class="layui-input-block">
                            <input type="text" disabled id="enginid_name" class="layui-input disabled">
                        </div>
                    </div>
                    <div class="layui-col-md6">
                        <label class="layui-form-label">关联整改通知</label>
                        <div class="layui-input-block">
                            <input type="text" disabled id="number" class="layui-input disabled">
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md6">
                        <label class="layui-form-label">整改负责人</label>
                        <div class="layui-input-block">
                            <input type="text" disabled id="fuzeer_name" class="layui-input disabled">
                        </div>
                    </div>
                    <div class="layui-col-md6">
                        <label class="layui-form-label"><text>*</text>整改完成时间</label>
                        <div class="layui-input-block">
                            <input type="text" name="gaidt" id="gaidt" readonly placeholder="请选择" clearable  autocomplete="off" class="layui-input bdate_ymd">
                        </div>
                    </div>
                </div>
            </div>
        </div>

        <div class="block-generic" id="mmlist">
            <div class="mmtit colorlan">需整改的问题：</div>
            <div class="mmtit colorlan">整改回复：</div>
            <div style="clear: both"></div>

            <div id="list_list">

            </div>
<!--            <div class="hang">-->
<!--                <div id="mmleft">-->
<!--                    <div class="layui-form-item">-->
<!--                        <div class="layui-row layui-col-space10">-->
<!--                            <div class="layui-col-md12">-->
<!--                                <label class="layui-form-label colorlan">检查项1</label>-->
<!--                                <div class="layui-input-block mmlock">-->
<!--                                    <div class="con">阿三大苏打</div>-->
<!--                                </div>-->
<!--                            </div>-->
<!--                        </div>-->
<!--                    </div>-->
<!--                    <div class="layui-form-item">-->
<!--                        <div class="layui-row layui-col-space10">-->
<!--                            <div class="layui-col-md12">-->
<!--                                <label class="layui-form-label">整改措施</label>-->
<!--                                <div class="layui-input-block mmlock">-->
<!--                                    <div class="con">阿三大苏打</div>-->
<!--                                </div>-->
<!--                            </div>-->
<!--                        </div>-->
<!--                    </div>-->
<!--                    <div class="layui-form-item">-->
<!--                        <div class="layui-row layui-col-space10">-->
<!--                            <div class="layui-col-md12">-->
<!--                                <label class="layui-form-label">现场图片(整改前)</label>-->
<!--                                <div class="layui-input-block">-->
<!--                                    <div id="minfiles"><div class="show-minimg"></div></div>-->
<!--                                </div>-->
<!--                            </div>-->
<!--                        </div>-->
<!--                    </div>-->
<!--                </div>-->
<!--                <div id="mmright">-->
<!--                    <div class="layui-form-item">-->
<!--                        <div class="layui-row layui-col-space10">-->
<!--                            <div class="layui-col-md12">-->
<!--                                <label class="layui-form-label"><text>*</text>是否整改</label>-->
<!--                                <div class="layui-input-block">-->
<!--                                    <select name="isgai">-->
<!--                                        <option value="">请选择</option>-->
<!--                                        <option value="整改已完成">整改已完成</option>-->
<!--                                        <option value="整改未完成">整改未完成</option>-->
<!--                                    </select>-->
<!--                                </div>-->
<!--                            </div>-->
<!--                        </div>-->
<!--                    </div>-->
<!--                    <div class="layui-form-item">-->
<!--                        <div class="layui-row layui-col-space10">-->
<!--                            <div class="layui-col-md12">-->
<!--                                <label class="layui-form-label">整改说明</label>-->
<!--                                <div class="layui-input-block">-->
<!--                                    <input type="text" name="gaishuo" clearable class="layui-input">-->
<!--                                </div>-->
<!--                            </div>-->
<!--                        </div>-->
<!--                    </div>-->
<!--                </div>-->
<!--                <div style="clear: both"></div>-->
<!--            </div>-->

        </div>


        <div class="block-generic">
            <div class="layui-form-item height_auto">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md12">
                        <label class="layui-form-label label_textarea">其他说明</label>
                        <div class="layui-input-block">
                            <textarea id="gaicon" name="gaicon" placeholder="请输入" class="layui-textarea"></textarea>
                        </div>
                    </div>
                </div>
            </div>

            <?php include '../public/upinfo.php'?>
        </div>


    </div>
</form>
<script>
    var param_id = getQueryVariable('id') || 0;

    $("#commentForm").validate({
        rules: {
            gaidt: {required: true},
        },
        messages:{
            gaidt: {required: "请选择"},
        }
    });





    layui.use(['laytp', 'form'], function() {
        var form = layui.form, layer = layui.layer;
        render_input_attr();

        facade.ajax({type: 'get', url: ask_engin_zheng_gai, data:{id:param_id}}).done(function(res){
            if (res.code === 2000) {
                var data = res.data.data;
                var engininfo = res.data.engininfo;

                $("#enginid_name").val(engininfo.name);

                $("#number").val(data.number);
                $("#fuzeer_name").val(data.fuzeer_name);
                $("#gaidt").val(data.gaidt);
                $("#gaicon").val(data.gaicon);










                var list = res.data.list;
                if(list.length > 0){
                    for (var key in list){
                        var str = '';
                        var nums = parseInt(key)+1;
                        str += '<div class="hang">';
                        str += '<div id="mmleft">';

                        str += '<div class="layui-form-item">';
                        str += '<div class="layui-row layui-col-space10">';
                        str += '<div class="layui-col-md12">';
                        str += '<label class="layui-form-label colorlan">检查项'+nums+'</label>';
                        str += '<div class="layui-input-block mmlock">';
                        str += '<div class="con">'+list[key].jiantype+'：'+list[key].name+'（说明：'+list[key].shuo+'）</div>';
                        str += '</div>';
                        str += '</div>';

                        if(list[key].fuguo == '不通过'){
                            str += '<div class="colorhong layui-layer-tips" style="margin: 5px 0 5px 135px">';
                            str += '<text>！复检未通过，查看原因</text>';
                            str += '<text class="layui-hide datatips">'+list[key].fushuo+'</text>';
                            str += '</div>';
                        }


                        str += '</div>';
                        str += '</div>';

                        str += '<div class="layui-form-item">';
                        str += '<div class="layui-row layui-col-space10">';
                        str += '<div class="layui-col-md12">';
                        str += '<label class="layui-form-label">整改措施</label>';
                        str += '<div class="layui-input-block mmlock">';
                        str += '<div class="con">'+list[key].gaicon+'</div>';
                        str += '</div>';
                        str += '</div>';
                        str += '</div>';
                        str += '</div>';

                        str += '<div class="layui-form-item">';
                        str += '<div class="layui-row layui-col-space10">';
                        str += '<div class="layui-col-md12">';
                        str += '<label class="layui-form-label">现场图片(整改前)</label>';
                        str += '<div class="layui-input-block">';
                        str += '<div id="minfilesLeft'+nums+'"><div class="show-minimg"></div></div>';
                        str += '</div>';
                        str += '</div>';
                        str += '</div>';
                        str += '</div>';

                        str += '</div>';
                        str += '<div id="mmright">';
                        str += '<div class="layui-form-item">';
                        str += '<div class="layui-row layui-col-space10">';
                        str += '<div class="layui-col-md12">';
                        str += '<label class="layui-form-label"><text>*</text>是否整改</label>';
                        str += '<div class="layui-input-block">';
                        str += '<select class="isgai">';
                        str += '<option value="">请选择</option>';
                        str += '<option value="整改已完成" '+ (list[key].isgai == '整改已完成' ? 'selected' : '') +'>整改已完成</option>';
                        str += '<option value="整改未完成" '+ (list[key].isgai == '整改未完成' ? 'selected' : '') +'>整改未完成</option>';
                        str += ' </select>';
                        str += '</div>';
                        str += '</div>';
                        str += '</div>';
                        str += '</div>';

                        str += '<div class="layui-form-item">';
                        str += '<div class="layui-row layui-col-space10">';
                        str += '<div class="layui-col-md12">';
                        str += '<label class="layui-form-label">整改说明</label>';
                        str += '<div class="layui-input-block">';
                        str += ' <input type="hidden" class="layui-input listid" value="'+list[key].id+'" nums="'+nums+'">';
                        str += ' <input type="text" placeholder="请输入" value="'+list[key].gaishuo+'" clearable autocomplete="off" class="layui-input gaishuo">';
                        str += '</div>';
                        str += '</div>';
                        str += '</div>';
                        str += '</div>';

                        str += '<div class="layui-form-item">';
                        str += '<div class="layui-row layui-col-space10">';
                        str += '<div class="layui-col-md12">';
                        str += '<label class="layui-form-label">现场图片(整改后)</label>';
                        str += '<div class="layui-input-block">';
                        str += '<div id="minfilesRight'+nums+'"><div class="show-minimg">';
                        str += '<div class="li addfilediv">';
                        str += '<div class="imgdiv upload_file_btn">';
                        str += '<i class="fa fa-plus jia"></i>';
                        str += '</div><div class="filetit">上传附件</div></div>';
                        str += '</div></div>';
                        str += '</div>';
                        str += '</div>';
                        str += '</div>';
                        str += '</div>';
                        str += '</div>';
                        str += '<div style="clear: both"></div>';
                        str += '</div>';

                        $("#list_list").append(str);
                        public_min_file_load_mm('minfilesLeft'+nums, list[key].filearr);
                        public_min_file_load_mm('minfilesRight'+nums, list[key].gaifilearr, 1);
                    }
                }


                public_upload_file_load('upload_files', res.data.files);
                render_from();
                initParseMoney();
            }
        });


        var layerTips = function (obj,cl) {
            var tip_index;
            var msg = $(obj).find('.datatips').text();
            if(!cl){
                tip_index = layer.tips(msg, obj, {tipsMore: true, time: 0, tips: 3});
            }else{
                layer.closeAll();
            }
        }
        $(document).on('mouseenter', '.layui-layer-tips', function () {
            layerTips(this);
        }).on('mouseleave', ' .layui-layer-tips', function () {
            layerTips(this,1);
        });


        form.on('submit(add)', function(data){
            parseMoney(data);

            var validRes = $("#commentForm").valid();
            if(!validRes){return false;}


            var list = [''];
            try {
                $('#list_list .hang').each(function (i) {
                    var id = $(this).find('.listid').val();
                    var nums = $(this).find('.listid').attr('nums');
                    var isgai = $(this).find('.isgai').val();
                    var gaishuo = $(this).find('.gaishuo').val();
                    var gaifiles = public_min_file_value_mm('minfilesRight'+nums);

                    var index = i + 1;
                    if(!isgai){
                        throw new Error('检查项'+index+'，请选择是否整改');
                    }




                    list.push({
                        id:id,
                        isgai:isgai,
                        gaishuo:gaishuo,
                        gaifiles:gaifiles,
                    });
                });
            } catch(e) {
                facade.error(e.message);
                return false;
            }
            data.field.list = list;


            data.field.files = public_upload_file_value('upload_files');
            data.field.id = param_id;
            data = parseMoney(data);
            facade.ajax({url: ask_engin_zheng_gai, data:data.field}).done(function(res){
                if (res.code === 2000) {
                    dataPostTimeOut();
                }
            });

            return false;
        });

    });











    function public_min_file_value_mm(dom) {
        var files = [];
        $('#'+dom+' .show-minimg .li').each(function(){
            var fileid = $(this).attr('id') || '';
            if(fileid){
                files.push(fileid);
            }
        });
        return files.join(',');
    }



    function public_min_file_load_mm(dom, data=[], isedit=0) {
        $("#"+dom).find('.upload_file_btn').click(function () {
            upload_min_file_btn_mm(dom);
        });
        if(data.length > 0){
            for (var key in data){
                var filename = data[key].name;
                var filepath = data[key].encpath;
                var fileurl = get_file_complete(filepath);
                var id = data[key].id;
                var fileext = data[key].ext;

                var imgstr = '';
                imgstr += '<div class="li" id='+id+'>';
                imgstr += '<div class="imgdiv">';
                if(fileext == 'png' || fileext == 'pneg' || fileext == 'jpg' || fileext == 'jpeg' || fileext == 'gif'){
                    imgstr += '<img src="'+fileurl+'" data_src="'+fileurl+'">';
                }else if(fileext == 'pdf'){
                    imgstr += '<div class="dea-ext" onclick="upload_files_viewer_pdf_show(\''+fileurl+'\')">'+fileext+'</div>';
                }else if(fileext == 'doc' || fileext == 'docx' || fileext == 'xls' || fileext == 'xlsx' || fileext == 'ppt' || fileext == 'pptx'){
                    imgstr += '<div class="dea-ext" onclick="upload_files_vieweroffice_show(\''+fileurl+'\')">'+fileext+'</div>';
                }else{
                    imgstr += '<div class="dea-ext" onclick="upload_files_show_yulan_not()">'+fileext+'</div>';
                }
                imgstr += '</div>';
                imgstr += '<div class="filetit">'+filename+'</div>';
                if(isedit > 0){
                    imgstr += '<span class="cheng">';
                    imgstr += '<i class="fa fa-times-circle shan" onclick="upload_min_del_file_mm(\''+dom+'\','+id+')"></i>';
                    imgstr += '</span>';
                }
                imgstr += '</div>';
                $('#'+dom+' .show-minimg').append(imgstr);
            }

            upload_min_file_viewer_mm(dom)
        }

        upload_min_init_mouse_mm(dom);
    }

    function upload_min_file_btn_mm(dom, isimg=0){
        layui.use('layer',function(){
            var layer = layui.layer;
            layer.open({
                type: 2,
                title: '上传文件',
                maxmin: true,
                area: ['600px', '400px'],
                content: './upload_min.php?isimg='+isimg+'&dom='+dom,
                cancel :function (index) {
                    layer.confirm("正在上传文件信息，是否直接关闭窗口？",function (conindex) {
                        layer.close(conindex);
                        layer.close(index);
                    });
                    return false;
                }
            });
        });
    }


    var viewerMinObj={}
    function upload_min_file_viewer_mm(dom){
        viewerMinObj[dom] = new Viewer(document.getElementById(dom));
    }

    function upload_min_del_file_mm(dom, id){
        layer.confirm('确定要删除该文件吗？',function(index){
            $("#"+dom+" .show-minimg .li").each(function () {
                if($(this).attr('id') == id){
                    $(this).remove();
                }
            });

            upload_min_file_viewer_mm(dom);
            layer.close(index);
        });
    }


    function upload_min_init_mouse_mm(dom) {
        $("#"+dom+" .show-minimg .li").on("mouseover",function(){
            $(this).find('.filetit').addClass('colorlan');
            $(this).find('.cheng').show();
            $(this).addClass('lilan');
        });
        $("#"+dom+" .show-minimg .li").on("mouseout",function(){
            $(this).find('.filetit').removeClass('colorlan');
            $(this).find('.cheng').hide();
            $(this).removeClass('lilan');
        });
    }


</script>
</body>
</html>
